package org.example.springboot.dao.impl;


import org.example.springboot.dao.Shop_Cart_ProductDao;
import org.example.springboot.entity.Shop_Cart_Product;
import org.example.springboot.util.JDBCUtils;

import java.util.List;

//s_shop_cart_product
public class Shop_Cart_ProductDaoImpl implements Shop_Cart_ProductDao {
    @Override
    public Boolean insert(Shop_Cart_Product shopCartProduct) {
        int rows= JDBCUtils.executeUpdate("insert into s_shop_cart_product(id,shop_cart_id,product_id,product_num) values(?,?,?,?)",
                shopCartProduct.getProduct_id(),shopCartProduct.getShop_cart_id(),shopCartProduct.getProduct_id(),shopCartProduct.getProduct_num());
        return rows>0;
    }

    @Override
    public Boolean update(Shop_Cart_Product shopCartProduct) {
        int rows= JDBCUtils.executeUpdate("update s_shop_cart_product set shop_cart_id=?,product_id=?,product_num=? where id=?",
                shopCartProduct.getShop_cart_id(),shopCartProduct.getProduct_id(),shopCartProduct.getProduct_num(),shopCartProduct.getProduct_id());
        return rows>0;
    }

    @Override
    public Boolean delete(String id) {
        int rows= JDBCUtils.executeUpdate("delete from s_shop_cart_product where id=?",id);
        return rows>0;
    }

    @Override
    public List<Shop_Cart_Product> selectAll() {
        return JDBCUtils.executeQuery(Shop_Cart_Product.class,"select * from s_shop_cart_product");
    }

    @Override
    public Integer selectCount() {
        return JDBCUtils.executeCount("select count(*) from s_shop_cart_product");
    }

    @Override
    public List<Shop_Cart_Product> selectLimit(int start, int rows) {
        return JDBCUtils.executeQuery(Shop_Cart_Product.class,"select * from s_shop_cart_product limit ?,?",start,rows);
    }
}
